<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>-->
    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script src="http://passport.cnblogs.com/scripts/jsencrypt.min.js"></script>
    <script src="../js/aes.js"></script>
</head>
<body>
<form action="<%=basePath %>login?action=goAES" id="login" name="form" method="post">
    <h1>Log In</h1>
    <fieldset   id="inputs">
        <input  id="name"  type="text" placeholder="Username" value="" autofocus required>
        <!-- ming -->
        <input  id="pwd" name="pwd" type="password" placeholder="Password" value=""  required>
    </fieldset>
    <fieldset id="actions">
        <input type="button" id="button" onclick="go()"  value="登 录">
        <a href="#" id="msg"></a>
    </fieldset>
    <input type="hidden" name="key" id="key">
    <!-- 密钥 -->
    <input type="hidden" id="msg_source" value="0807060504030201">
</form>
</body>
<script type="text/javascript">

    function go(){
        if(isEmptyById(['name','pwd'])){
            $('#msg').text('用户名或密码不能为空');
            return;
        }
        //var pwd = $("#pwd").val();
        //console.info("加密前  ： "+pwd);
        //CryptoJS.AES.encrypt('明文','key');
        //var ecodeRestult = CryptoJS.AES.encrypt($("#pwd").val(),$("#msg_source").val());
        //console.info("加密后  ："+ecodeRestult);
        //$("#pwd").val(ecodeRestult);
        //CryptoJS.AES.decrypt('密文','key').toString(CryptoJS.enc.Utf8);
        //var decodeResult = CryptoJS.AES.decrypt(ecodeRestult,$("#msg_source").val()).toString(CryptoJS.enc.Utf8);
        //console.info("解密后  ："+decodeResult);
        var pwd = $("#pwd").val();
        var key  = CryptoJS.enc.Utf8.parse($("#msg_source").val());
        var iv   = CryptoJS.enc.Utf8.parse($("#msg_source").val());
        var srcs = CryptoJS.enc.Utf8.parse(pwd);
        var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv,mode:CryptoJS.mode.CBC});
        $("#pwd").val(encrypted);
        $('#login').submit();
    }
</script>
 <script type="text/javascript">
        function go(){
            if(isEmptyById(['name','pwd'])){
                        $('#msg').text('用户名或密码不能为空');
                       return;
                   }
             var modulus = $('#hid_modulus').val(), exponent = $('#hid_exponent').val();
               var key = RSAUtils.getKeyPair(exponent, '', modulus);
                var key2="name="+$('#name').val()+"&pwd="+$('#pwd').val();
              $('#key').val(RSAUtils.encryptedString(key, key2));
                $('#login').submit();
             }
 </script>
</html>